//
//  TMShareManager.m
//  国学商家管理
//
//  Created by Tao Li on 2018/6/23.
//  Copyright © 2018年 mac. All rights reserved.
//

#import "TMShareManager.h"
#import <UMShare/UMShare.h>
@implementation TMShareManager
static TMShareManager * manager;
+ (instancetype) defaultManager{
    if (!manager){
        static dispatch_once_t onceToken;
        dispatch_once(&onceToken, ^{
            manager = [[TMShareManager alloc] init];
        });
    }
    return manager;
}
- (void)shareToQQWithParam:(NSDictionary *)param Success:(ShareSuccessBlock)block{
    UMShareWebpageObject *shareObject = [UMShareWebpageObject shareObjectWithTitle:param[@"title"] descr:param[@"discript"] thumImage:param[@"image"]];
    shareObject.webpageUrl = @"http://103.10.85.152/index.php/api/pub/invites";
    
    UMSocialMessageObject *messageObject = [UMSocialMessageObject messageObject];
    messageObject.shareObject = shareObject;
    
    [[UMSocialManager defaultManager] shareToPlatform:UMSocialPlatformType_QQ messageObject:messageObject currentViewController:nil completion:^(id data, NSError *error) {
        if (error) {
            NSLog(@"************Share fail with error %@*********",error);
        }else {
            block(@"分享成功");
        }
    }];
}
- (void)shareToQQZoneWithParam:(NSDictionary *)param Success:(ShareSuccessBlock)block{
    UMShareWebpageObject *shareObject = [UMShareWebpageObject shareObjectWithTitle:param[@"title"] descr:param[@"discript"] thumImage:param[@"image"]];
    shareObject.webpageUrl = @"http://103.10.85.152/index.php/api/pub/invites";
    
    UMSocialMessageObject *messageObject = [UMSocialMessageObject messageObject];
    messageObject.shareObject = shareObject;
    
    [[UMSocialManager defaultManager] shareToPlatform:UMSocialPlatformType_Qzone messageObject:messageObject currentViewController:nil completion:^(id data, NSError *error) {
        if (error) {
            NSLog(@"************Share fail with error %@*********",error);
        }else {
            block(@"分享成功");
        }
    }];
}



//pengyou quan
- (void)shareToWXCWithParam:(NSDictionary *)param Success:(ShareSuccessBlock)block{
    //    @"image":weakself.imageView.image,@"discript":@"我邀请你来注册app",@"title":@"测试"
    UMShareWebpageObject *shareObject = [UMShareWebpageObject shareObjectWithTitle:param[@"title"] descr:param[@"discript"] thumImage:param[@"image"]];
    shareObject.webpageUrl = @"http://103.10.85.152/index.php/api/pub/invites";
    
    UMSocialMessageObject *messageObject = [UMSocialMessageObject messageObject];
    messageObject.shareObject = shareObject;
    
    [[UMSocialManager defaultManager] shareToPlatform:UMSocialPlatformType_WechatTimeLine messageObject:messageObject currentViewController:nil completion:^(id data, NSError *error) {
        if (error) {
            NSLog(@"************Share fail with error %@*********",error);
        }else {
            [TMProgressHUD showSuccessWithStatus:@"分享成功"];
            block(@"分享成功");
            
        }
    }];
}
- (void)shareToWXWithParam:(NSDictionary *)param Success:(ShareSuccessBlock)block{
    //    @"image":weakself.imageView.image,@"discript":@"我邀请你来注册app",@"title":@"测试"
    UMShareWebpageObject *shareObject = [UMShareWebpageObject shareObjectWithTitle:param[@"title"] descr:param[@"discript"] thumImage:param[@"image"]];
    shareObject.webpageUrl = @"http://app.yxp123.com/home/pub/invites";
    
    UMSocialMessageObject *messageObject = [UMSocialMessageObject messageObject];
    messageObject.shareObject = shareObject;
    
    [[UMSocialManager defaultManager] shareToPlatform:UMSocialPlatformType_WechatSession messageObject:messageObject currentViewController:nil completion:^(id data, NSError *error) {
        if (error) {
            NSLog(@"************Share fail with error %@*********",error);
        }else {
            [TMProgressHUD showSuccessWithStatus:@"分享成功"];
            block(@"分享成功");
            
        }
    }];
}


- (void)shareToWBWithParam:(NSDictionary *)param Success:(ShareSuccessBlock)block{
    UMShareWebpageObject *shareObject = [UMShareWebpageObject shareObjectWithTitle:@"" descr:@"" thumImage:@""];
    shareObject.webpageUrl = @"";
    
    UMSocialMessageObject *messageObject = [UMSocialMessageObject messageObject];
    messageObject.shareObject = shareObject;
    
    [[UMSocialManager defaultManager] shareToPlatform:UMSocialPlatformType_Sina messageObject:messageObject currentViewController:self completion:^(id data, NSError *error) {
        if (error) {
            NSLog(@"************Share fail with error %@*********",error);
        }else {
            block(@"分享成功");
        }
    }];
}
- (void)loginWithQQSuccess:(ShareSuccessBlock)block{
    /**
     设置QQ授权登录
     @param platformType 平台
     @param result 授权成功
     @param error 授权失败
     */
    [[UMSocialManager defaultManager] getUserInfoWithPlatform:UMSocialPlatformType_QQ currentViewController:nil completion:^(id result, NSError *error) {
        if (error) {
        } else {
            UMSocialUserInfoResponse *resp = result;
            // 授权信息
            NSLog(@"QQ uid: %@", resp.uid);
            NSLog(@"QQ openid: %@", resp.openid);
            NSLog(@"QQ accessToken: %@", resp.accessToken);
            NSLog(@"QQ expiration: %@", resp.expiration);
            // 用户信息
            NSLog(@"QQ name: %@", resp.name);
            NSLog(@"QQ iconurl: %@", resp.iconurl);
            NSLog(@"QQ gender: %@", resp.gender);
            // 第三方平台SDK源数据
            NSLog(@"QQ originalResponse: %@", resp.originalResponse);
            block(resp);
        }
    }];
}
- (void)loginWithWXSuccess:(ShareSuccessBlock)block{
    [[UMSocialManager defaultManager] getUserInfoWithPlatform:UMSocialPlatformType_WechatSession currentViewController:nil completion:^(id result, NSError *error) {
        if (error) {
            NSLog(@"%@", error);
        } else {
            UMSocialUserInfoResponse *resp = result;
            // 授权信息
            NSLog(@"Wechat uid: %@", resp.uid);
            NSLog(@"Wechat openid: %@", resp.openid);
            NSLog(@"Wechat accessToken: %@", resp.accessToken);
            NSLog(@"Wechat refreshToken: %@", resp.refreshToken);
            NSLog(@"Wechat expiration: %@", resp.expiration);
            // 用户信息
            NSLog(@"Wechat name: %@", resp.name);
            NSLog(@"Wechat iconurl: %@", resp.iconurl);
            NSLog(@"Wechat gender: %@", resp.gender);
            // 第三方平台SDK源数据
            NSLog(@"Wechat originalResponse: %@", resp.originalResponse);
            block(resp);
        }
    }];
}
- (void)loginWithWBSuccess:(ShareSuccessBlock)block{
    [[UMSocialManager defaultManager] getUserInfoWithPlatform:UMSocialPlatformType_Sina currentViewController:self completion:^(id result, NSError *error) {
        UMSocialUserInfoResponse *resp = result;
        // 第三方登录数据(为空表示平台未提供)
        // 授权数据
        NSLog(@" uid: %@", resp.uid);
        NSLog(@" openid: %@", resp.openid);
        NSLog(@" accessToken: %@", resp.accessToken);
        NSLog(@" refreshToken: %@", resp.refreshToken);
        NSLog(@" expiration: %@", resp.expiration);
        // 用户数据
        NSLog(@" name: %@", resp.name);
        NSLog(@" iconurl: %@", resp.iconurl);
        NSLog(@" gender: %@", resp.gender);
        // 第三方平台SDK原始数据
        NSLog(@" originalResponse: %@", resp.originalResponse);//name image openid
        block(resp);
    }];
}


@end
